package com.web.hilover.service.impl;

import com.web.hilover.mapper.UserMapper;
import com.web.hilover.mapper.CoupleMapper;
import com.web.hilover.mapper.CommentMapper;
import com.web.hilover.mapper.QuoteMapper;
import com.web.hilover.service.StatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class StatServiceImpl implements StatService {
    
    @Autowired
    private UserMapper userMapper;
    
    @Autowired
    private CoupleMapper coupleMapper;
    
    @Autowired
    private CommentMapper commentMapper;
    
    @Autowired
    private QuoteMapper quoteMapper;
    
    @Override
    public Map<String, Integer> getDashboardStats() {
        Map<String, Integer> stats = new HashMap<>();
        
        try {
            stats.put("userCount", userMapper.count());
            stats.put("coupleCount", coupleMapper.count());
            stats.put("commentCount", commentMapper.count());
            stats.put("quoteCount", quoteMapper.count());
        } catch (Exception e) {
            log.error("获取统计数据失败", e);
        }
        
        return stats;
    }
    
    @Override
    public Map<String, Object> getRecentActivities() {
        Map<String, Object> activities = new HashMap<>();
        
        try {
            List<Map<String, Object>> recentComments = commentMapper.findRecentWithDetail(5);
            List<Map<String, Object>> recentCouples = coupleMapper.findRecentWithDetail(5);
            
            activities.put("recentComments", recentComments);
            activities.put("recentCouples", recentCouples);
        } catch (Exception e) {
            log.error("获取最近活动失败", e);
        }
        
        return activities;
    }
} 